from PySide6.QtCore import Qt
from PySide6.QtWidgets import QSlider, QStyle

class MySlider(QSlider):
    def __init__(self, parent = None):
        super().__init__(parent)
        self.setPageStep(0)

    def mousePressEvent(self, ev):
        if Qt.LeftButton == ev.button():
            value = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), ev.pos().x(), self.width())
            self.setValue(value)

        #滑动条移动事件等事件也用到了mousePressEvent,加这句话是为了不对其产生影响，使得Slider能正常相应其他鼠标事件
        super().mousePressEvent(ev)


